package com.cloud.www.service.impl;

import com.cloud.www.model.entity.MLanguage;
import com.cloud.www.mapper.MLanguageMapper;
import com.cloud.www.service.MLanguageService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * 语言
 *
 * @author douhaichao code generator
 * @date 2022-10-04 09:32:39
 */
@Service
@AllArgsConstructor
public class MLanguageServiceImpl extends ServiceImpl<MLanguageMapper, MLanguage> implements MLanguageService {

    /**
   * 根据对象属性查找满足条件的第一条数据     *      * @return
   */
    @Override
    public MLanguage selectOne(MLanguage req) {
        QueryWrapper queryWrapper = new QueryWrapper<MLanguage>();
        queryWrapper.setEntity(req);
        return baseMapper.selectOne(queryWrapper);
    }

    /**
     * 根据条件查询所有
     */
    @Override
    public List<MLanguage> selectAll(MLanguage req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectList(queryWrapper);
    }

    /**
     * 根据对象查询所有分页数据(精确查询)     *      * @return
     */
    @Override
    public IPage<MLanguage> selectPage(Page page, MLanguage req) {
        IPage<MLanguage> list = baseMapper.selectPage(
                page,
                new QueryWrapper<MLanguage>().setEntity(req));
        return list;
    }

    /**
     * 根据对象查询所有分页数据(模糊查询)     *      * @return
     */
    @Override
    public IPage<MLanguage> selectPageByLike(Page page, MLanguage req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        
                                        if (null !=req.getId()) {
                    queryWrapper.eq("id" , req.getId());
                }
                    
                            if (!StrUtil.isEmpty(req.getTypeName())) {
                    queryWrapper.like("type_name" , req.getTypeName());
                }
                                
                                        if (null !=req.getSort()) {
                    queryWrapper.eq("sort" , req.getSort());
                }
                    
                                        if (null !=req.getIsDel()) {
                    queryWrapper.eq("is_del" , req.getIsDel());
                }
                    
                                        if (null !=req.getCreateTime()) {
                    queryWrapper.eq("create_time" , req.getCreateTime());
                }
                    
                                        if (null !=req.getUpdateTime()) {
                    queryWrapper.eq("update_time" , req.getUpdateTime());
                }
                            IPage<MLanguage> list = baseMapper.selectPage(page, queryWrapper);
        return list;
    }

    /**
     * 根据条件统计数据量     *      * @return
     */
    @Override
    public int count(MLanguage req) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.setEntity(req);
        return baseMapper.selectCount(queryWrapper);
    }
}
